﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using ITProject.Repository.Concrete;
using ITProject.Repository.Abstract;

namespace ITProject.WebUI.Infrastructure
{
    /// <summary>
    /// Klasa będąca fabryką kontrolerów, binduje interfejsy na konkretne implementacje.
    /// Autor: Jakub Szatkowski
    /// </summary>
    public class NinjectFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;

        public NinjectFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            ninjectKernel.Bind<IProjectRepository>().To<ProjectRepository>();
            ninjectKernel.Bind<IMessageRepository>().To<MessageRepository>();
            ninjectKernel.Bind<IUserRepository>().To<UserRepository>();
            ninjectKernel.Bind<ISVNRepository>().To<SVNRepository>();
        }
    }
}